package com.news.servlet.admin;

import com.news.service.NewsService;
import com.news.service.impl.NewsServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/dashboard")
public class DashboardServlet extends HttpServlet {
    private NewsService newsService = new NewsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 获取统计数据
        int totalNews = newsService.getTotalNewsCount();
        int totalUsers = newsService.getTotalUserCount();
        int totalSorts = newsService.getTotalSortCount();

        // 设置属性
        request.setAttribute("totalNews", totalNews);
        request.setAttribute("totalUsers", totalUsers);
        request.setAttribute("totalSorts", totalSorts);

        // 转发到控制台页面
        request.getRequestDispatcher("admin_index.jsp").forward(request, response);
    }
} 